package com.example.trader_svc.service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.trader_svc.model.PriceAdjustment;
import com.example.trader_svc.model.TraderLog;
import com.example.trader_svc.repository.TraderLogRepository;

@Service
public class TraderService {

    @Autowired
    private TraderLogRepository logRepository;

    public BigDecimal calculatePrice(PriceAdjustment adj) {
        BigDecimal result = adj.getBasePrice().multiply(adj.getMarketFactor());
        TraderLog log = new TraderLog();
        log.setBondCode(adj.getBondCode());
        log.setFinalPrice(result);
        log.setAdjustedTime(LocalDateTime.now());
        logRepository.save(log);
        return result;
    }

    public List<TraderLog> getLogs(String bondCode) {
        return logRepository.findByBondCode(bondCode);
    }
}
